﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataAccessLayer;
using BussinessLogicLayer;

#region import form
using QLThongTinGiaiDauBongDa.Presentation.frmGiaiDau;
using QLThongTinGiaiDauBongDa.Presentation.frmNguoiDung;
using QLThongTinGiaiDauBongDa.Presentation.frmKhoa;
using QLThongTinGiaiDauBongDa.Presentation.frmCauThu;
using QLThongTinGiaiDauBongDa.Presentation.frmDoiBong;
using QLThongTinGiaiDauBongDa.Presentation.frmTranDau;
using QLThongTinGiaiDauBongDa.Presentation.frmTrongTai;
using QLThongTinGiaiDauBongDa.Presentation.frmTaiTro;
using QLThongTinGiaiDauBongDa.Presentation.frmPhanThuong;
using QLThongTinGiaiDauBongDa.Presentation.frmHeThong;
using DevComponents.DotNetBar;
#endregion

namespace QLThongTinGiaiDauBongDa
{
    public partial class frmChinh : DevComponents.DotNetBar.Metro.MetroAppForm
    {
        public frmChinh()
        {
            InitializeComponent();
        }
        // Thuoc tinh
        QuanLyGiaiDauDataContext DB = new QuanLyGiaiDauDataContext();

        #region Hien thi form
        // Xu ly btn Vong Dau
        private void btnLuotSlide_Click(object sender, EventArgs e)
        {
            if (SlideTTGD.SelectedPage == pspKetQua)
                SlideTTGD.SelectedPage = pspVongLoai;
            else
                if (SlideTTGD.SelectedPage == pspVongLoai)
                    SlideTTGD.SelectedPage = pspVongTrong;
                else
                    if (SlideTTGD.SelectedPage == pspVongTrong)
                        SlideTTGD.SelectedPage = pspKetQua;
        }
        // Xu ly dang nhap su dung chuc nang
        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            frmDangNhap frmDN = new frmDangNhap();
            frmDN.ShowDialog();
            if (frmDN.KiemTraDN)
            {
                string ten = frmDangNhap.TDNhap;
                lblChaoMung.Text = "Chào mừng bạn, " + ten +"!!!";
                btnDangXuat.Enabled = btnDMK.Enabled = true;
                int[] DSMa = NguoiDungBLL.LayMSNDTheoTenDN(ten).Select(nd => nd.MaNguoiDung).ToArray();
                foreach (int Ma in DSMa)
                    foreach (string TenQuyen in PhanQuyenBLL.BatChucNang(Ma).Select(q => q.TenQuyen).ToArray())
                        BatChucNang(TenQuyen);
            }
        }
        // Xu ly hien thi form quan ly giai dau
        private void btnQLGD_Click(object sender, EventArgs e)
        {
            frmQLGiaiDau frmQLGD = new frmQLGiaiDau();
            frmQLGD.Show();
        }
        // Xu ly hien thi form quan ly khoa
        private void btnQLKhoa_Click(object sender, EventArgs e)
        {
            frmQLKhoa frmQLK = new frmQLKhoa();
            frmQLK.Show();
        }
        // Xu ly hien thi form quan ly cau thu
        private void btnQLCT_Click(object sender, EventArgs e)
        {
            frmQLCauThu frmQLCT = new frmQLCauThu();
            frmQLCT.Show();
        }
        // Xu ly hien thi form quan ly doi bong
        private void btnQLDB_Click(object sender, EventArgs e)
        {
            frmQLDoiBong frmQLDB = new frmQLDoiBong();
            frmQLDB.Show();
        }
        // Xu ly hien thi form quan ly tran dau
        private void btnQLTD_Click(object sender, EventArgs e)
        {
            frmQLTranDau frmQLTD = new frmQLTranDau();
            frmQLTD.Show();
        }
        // Xu ly hien thi form quan ly trong tai
        private void btnQLTTai_Click(object sender, EventArgs e)
        {
            frmQLTrongTai frmQLTTai = new frmQLTrongTai();
            frmQLTTai.Show();
        }
        // Xu ly dang xuat he thong
        private void btnDangXuat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát chương trình??", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Application.Exit();
            }

        }
        // Xu ly hien thi form quan ly tai tro.
        private void btnQLTTro_Click(object sender, EventArgs e)
        {
            frmQLTaiTro frmQLTT = new frmQLTaiTro();
            frmQLTT.Show();
        }
        // Xu ly hien thi form quan ly phan thuong
        private void btnQLPThuong_Click(object sender, EventArgs e)
        {
            frmQLPhanThuong frmQLPT = new frmQLPhanThuong();
            frmQLPT.Show();
        }
        // Xu ly hien thi form quan ly nguoi dung
        private void btnQLND_Click(object sender, EventArgs e)
        {
            frmQLNguoiDung frmQLND = new frmQLNguoiDung();
            frmQLND.Show();
        }
        // Xu ly hien thi form quan ly he thong
        private void btnQLHT_Click(object sender, EventArgs e)
        {
            frmQLHeThong frmQLHT = new frmQLHeThong();
            frmQLHT.Show();
        }
        // Xu ly hien thi form quan ly doi mat khau
        private void btnDMK_Click(object sender, EventArgs e)
        {
            frmDoiMatKhau frmDMK = new frmDoiMatKhau();
        }
        // Xu ly hien thi form dat lai mat khau
        private void btnDLMK_Click(object sender, EventArgs e)
        {
            frmDatLaiMatKhau frmDLMK = new frmDatLaiMatKhau();
        }
        // Xu ly chuc nang thay doi giao dien
        private void btnTDGD_Click(object sender, EventArgs e)
        {
            cldTDGD.ShowDialog();
            this.smrFrmChinh.MetroColorParameters = new DevComponents.DotNetBar.Metro.ColorTables.MetroColorGeneratorParameters(cldTDGD.Color, Color.White);
            SlideTTGD.BackColor = cldTDGD.Color;
            gplGiaiDau.BackColor = Color.Red;

            // Thay doi giao dien
        }
        // Xu ly huong dan
        private void btnHuongDan_Click(object sender, EventArgs e)
        {
            // Huong Dan SU Dung.
        }
        // Xu ly gioi thieu
        private void btnGioiThieu_Click(object sender, EventArgs e)
        {
            // Gioi Thieu.
        }

        #endregion

        private void frmChinh_Load(object sender, EventArgs e)
        {
            SlideTTGD.SelectedPage = pspVongLoai;
            cbbXuatGiaiDau.DataSource = GiaiDauBLL.LayGiaiDau();
            cbbXuatGiaiDau.DisplayMember = "TenGiaiDau";
            cbbXuatGiaiDau.ValueMember = "MaGiaiDau";
            cbbXuatGiaiDau.SelectedIndexChanged+=cbbXuatGiaiDau_SelectedIndexChanged;
            HienThiGiaiDau();
        }
        private void HienThiGiaiDau()
        {
            lblTenGiaiDau.Text = cbbXuatGiaiDau.Text;
            lblTenGiaiDau.ForeColor = Color.Red;
            dgvVongLoai.DataSource = TranDauBLL.VongDau(Convert.ToInt32(cbbXuatGiaiDau.SelectedValue.ToString()),"Loại");
            dgvVongTrong.DataSource = TranDauBLL.VongDau(Convert.ToInt32(cbbXuatGiaiDau.SelectedValue.ToString()),"Trong");
            if (DoiBongBLL.LayBangDau("A").Count == 0)
            {
                lblBangA.Visible = false;
                dgvBangA.Visible = false;
            }
            if (DoiBongBLL.LayBangDau("B").Count == 0)
            {
                lblBangB.Visible = false;
                dgvBangB.Visible = false;
            }
            if (DoiBongBLL.LayBangDau("C").Count == 0)
            {
                lblBangC.Visible = false;
                dgvBangC.Visible = false;
            }
            if (DoiBongBLL.LayBangDau("D").Count == 0)
            {
                lblBangD.Visible = false;
                dgvBangD.Visible = false;
            }
            dgvBangA.DataSource = DoiBongBLL.LayBangDau("A");
            dgvBangB.DataSource = DoiBongBLL.LayBangDau("B");
            dgvBangC.DataSource = DoiBongBLL.LayBangDau("C");
            dgvBangD.DataSource = DoiBongBLL.LayBangDau("D");
        }
        private void cbbXuatGiaiDau_SelectedIndexChanged(object sender, EventArgs e)
        {
            HienThiGiaiDau();
        }
        // Xu ly phan quyen
        private void BatChucNang(string quyen)
        {
            switch (quyen)
            {
                case "QLGD":
                    btnQLGD.Enabled = true;
                    break;
                case "QLDB":
                    btnQLDB.Enabled = true;
                    break;
                case "QLCT":
                    btnQLCT.Enabled = true;
                    break;
                case "QLTTai":
                    btnQLTTai.Enabled = true;
                    break;
                case "QLKhoa":
                    btnQLKhoa.Enabled = true;
                    break;
                case "QLNDung":
                    btnQLND.Enabled = true;
                    break;
                case "QLHThong":
                    btnQLHT.Enabled = true;
                    break;
                case "QLPThuong":
                    btnQLPThuong.Enabled = true;
                    break;
                case "QLTTro":
                    btnQLTTro.Enabled = true;
                    break;
                case "QLTD":
                    btnQLTD.Enabled = true;
                    break;
            }
        }
    }
}